package com.im.server.enterprise.common.dao;

import java.util.ArrayList;
import java.util.List;

import org.springframework.stereotype.Repository;

import com.im.base.dao.BaseDAO;
import com.im.server.enterprise.common.bean.DepartmentChatContent;
import com.im.server.enterprise.common.bean.DepartmentChatItem;
import com.im.server.enterprise.common.data.DepartmentChatQuery;
import com.only.query.hibernate.QueryWrapper;
import com.only.query.hibernate.QueryOption;
import com.only.query.hibernate.QueryOptionType;
import com.only.query.page.QueryPage;
import com.only.query.hibernate.util.QueryUtil;

/**
 * @author: XiaHui
 * @date: 2016年8月19日 下午1:56:03
 */
@Repository
public class DepartmentChatDAO extends BaseDAO {

	String space = "departmentChat";

	public List<DepartmentChatContent> queryDepartmentChatContentList(DepartmentChatQuery departmentChatQuery, QueryPage queryPage) {
		QueryWrapper queryWrapper = new QueryWrapper();
		queryWrapper.setPage(queryPage);
		List<QueryOption> queryOption = new ArrayList<QueryOption>();
		queryOption.add(new QueryOption("text", QueryOptionType.likeAll));
		queryOption.add(new QueryOption("userNickname", QueryOptionType.likeAll));
		QueryUtil.getQueryWrapperType(departmentChatQuery, queryWrapper, queryOption);

		List<DepartmentChatContent> list = this.queryPageListByName(space + ".queryDepartmentChatContentList", queryWrapper, DepartmentChatContent.class);
		return list;
	}

	public List<DepartmentChatItem> queryDepartmentChatItemList(String text, QueryPage queryPage) {
		QueryWrapper queryWrapper = new QueryWrapper();
		queryWrapper.setPage(queryPage);
		List<QueryOption> queryOption = new ArrayList<QueryOption>();
		queryOption.add(new QueryOption("text", QueryOptionType.likeAll));
		queryWrapper.put("text", text);
		List<DepartmentChatItem> list = this.queryPageListByName(space + ".queryDepartmentChatItemList", queryWrapper, DepartmentChatItem.class);
		return list;
	}

	public List<DepartmentChatItem> getDepartmentChatItemListByMessageIds(List<String> messageIds) {
		QueryWrapper queryWrapper = new QueryWrapper();
		queryWrapper.addParameter("messageIds", messageIds);
		List<DepartmentChatItem> list = this.queryPageListByName(space + ".queryDepartmentChatItemList", queryWrapper, DepartmentChatItem.class);
		return list;
	}

	public List<DepartmentChatItem> getDepartmentChatItemListByContentIds(List<String> departmentChatContentIds) {
		QueryWrapper queryWrapper = new QueryWrapper();
		queryWrapper.addParameter("departmentChatContentIds", departmentChatContentIds);
		List<DepartmentChatItem> list = this.queryPageListByName(space + ".queryDepartmentChatItemList", queryWrapper, DepartmentChatItem.class);
		return list;
	}
}
